package com.zzwtec.obj.sizeof;

import java.lang.instrument.Instrumentation;

/**
 * 加载入口
 * @author Administrator
 *
 */
public class AgentMain {
    private static volatile Instrumentation ins;
    public static void premain(String args, Instrumentation inst) throws Exception {
        if (AgentMain.ins != null){
        	throw new AssertionError("Already initialized");
        }         	
        AgentMain.ins = inst;        

    }

    /*
    private static boolean supportsRetransform(Instrumentation instrumentation) throws Exception {
        for (Method m : instrumentation.getClass().getMethods()) {
            if ("isRetransformClassesSupported".equals(m.getName())) {
                return (Boolean) m.invoke(instrumentation);
            }
        }
        return false;
    }
    */
    private static void checkSetup() {
        if (ins == null ) {
          throw new IllegalStateException(String.valueOf("Instrumentation is not setup properly. "
                + "You have to pass -javaagent:path/to/object-explorer.jar to the java interpreter"));
        }        
    }
    public static Instrumentation instrumentation() {    	
        checkSetup();
        return ins;
    }
}
